public class Test2 {
    public static void main(String[] args) {
        int j = 0;
        for(double i = 2; i <= 20000 ;i++){
            if(Judge(i) == 1){
                j++;
                System.out.print((int) i + " ");
                if(j%5 == 0){
                    System.out.println();
                }
            }
        }
    }

    public static int Judge(double j){

        if(j ==2|| j==3 )
            return 1 ;
        //不在6的倍数两侧的一定不是质数
        if(j %6!= 1&&j %6!= 5)
            return 0 ;
        double tmp =Math.sqrt(j);
        //在6的倍数两侧的也可能不是质数
        for(int i = 5; i <= tmp; i += 6 )
            if(j %i== 0||j %(i+ 2) == 0 )
                return 0 ;
        return 1 ;
    }
}

